package com.yanqu.road.server.cmd.wingroom;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.connect.CrossAgentLinkedControl;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.wingroom.CrossWingRoomMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/3/24 21:03
 */
@Cmd(code = CrossProtocol.C_WING_ROOM_SYNC_EVENT_TO_CROSS, desc = "同步区服事件状态到跨服")
public class CrossSyncEventStatusFromServerCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.SyncCrossAllEventStatusMsg msg = WingRoomProto.SyncCrossAllEventStatusMsg.parseFrom(packet.getBytes());
        CrossWingRoomMgr.putEventData(msg);
        long serverId = CrossAgentLinkedControl.getLinkedClient(ctx).getServerId();
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_WING_ROOM_SYNC_ALL_EVENT_RESP);
        MessageHelper.sendPacket(serverId, 0, message);
    }
}
